import os

import cv2


# 需要opencv

def save_img():
    video_path = 'D:\\3'  # 需要剪裁视频的绝对位置
    videos = os.listdir(video_path)

    for video_name in videos:
        file_name = video_name.split('.')[0]
        folder_name = video_path + file_name
        os.makedirs(folder_name, exist_ok=True)
        vc = cv2.VideoCapture(video_path + '/' + video_name)
        c = 0
        rval = vc.isOpened()
        while rval:
            c = c + 1
            rval, frame = vc.read()
            pic_path = 'D:\\qwe\\'  # 存放按帧读取的图片位置
            if rval:
                img_path = pic_path + '\\' + video_name + '\\'
                os.makedirs(img_path, exist_ok=True)
                cv2.imwrite(img_path + str(c) + '.jpg', frame)

                print(pic_path + str(c))
                cv2.waitKey(0)
            else:
                break
        vc.release()
        print(str(c) + 'save_success')


save_img()
